package com.cloudkinto.controller.company;


import com.cloudkinto.base.BaseController;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.company.CompanyAuthorizeService;
import com.cloudkinto.service.company.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hua
 * @since 2024-09-09
 */
@RestController
@Api(tags = "Temu授权及其他API模块")
@RequestMapping("/api")
public class CompanyAuthorizeController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(CompanyAuthorizeController.class);

    @Autowired
    private CompanyAuthorizeService service;


    @UserSessionRequired
    @GetMapping("CompanyAuthorize/pageInit")
    @ApiOperation(value = "查询初始化", notes = "查询初始化")
    public SingleResult pageInit() {
        return service.pageInit(getCompanyId());
    }


    @UserSessionRequired
    @PostMapping("CompanyAuthorize/generateCustomAuthKey")
    @ApiOperation(value = "生成密钥/启用暂停密钥", notes = "生成密钥/启用暂停密钥")
    public SingleResult generateCustomAuthKey(@RequestBody @Validated CompanyAuthUpdateReq req) {
        Long userId = getCurrentUserId();
        Long companyId = getCompanyId();
        return SingleResult.success(service.generateCustomAuthKey(req, companyId, userId));
    }


    @UserSessionRequired
    @PostMapping("CompanyAuthorize/temuTokenInfoPush")
    @ApiOperation(value = "授权 token 推送到 Temu（前端调）", notes = "授权 token 推送到 Temu")
//    @ApiResponses(@ApiResponse(code = 200, message = "", response = ))
    public SingleResult temuTokenInfoPush(@RequestBody @Validated TemuAuthorizeReq req) {
        Long userId = getCurrentUserId();
        Long companyId = getCompanyId();
        return service.temuTokenInfoPush(req, companyId, userId);
    }
    @PostMapping("CompanyAuthorize/temuTokenInfoPush1")
    @ApiOperation(value = "授权 token 推送到 Temu（后端调）", notes = "授权 token 推送到 Temu")
//    @ApiResponses(@ApiResponse(code = 200, message = "", response = ))
    public String temuTokenInfoPush1(@RequestBody @Validated TemuAuthorizeReq req) {
        return service.temuTokenInfoPush1(req.getTicket(),req.getShopId(), req.getCompanyId());
    }

    @PostMapping("/bg/certified/warehouse/token/verify")
    @ApiOperation(value = "Temu向对接仓验证 token 的有效性", notes = "Temu向对接仓验证 token 的有效性")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = TemuAuthVerifyResponse.class))
    public TemuAuthVerifyResponse tokenVerify(@RequestBody @Validated TemuAuthTokenVerifyReq req) {
        TemuAuthVerifyResponse res = service.tokenVerifyApi(req);
        return res;
    }


    @PostMapping("/bg/certified/warehouse/skuInfos/list/get")
    @ApiOperation(value = "Temu向对接仓  商品查询", notes = "emu向对接仓  商品查询")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = ProductQueryResponse.class))
    public ProductQueryResponse getSkuInfoList(@RequestBody @Validated ProductQueryReq req) {
        return service.getSkuInfoList(req);
    }

    @PostMapping("/bg/certified/warehouse/skuInfos/details/get")
    @ApiOperation(value = "Temu向对接仓  商品查询", notes = "emu向对接仓  商品查询")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = ProductQueryDetailResponse.class))
    public TemuBaseQueryRes<ProductQueryDetailResponse> getSkuInfoDetail(@RequestBody @Validated ProductQueryReq req) {
        return service.getSkuInfoDetail(req);
    }


//    @UserSessionRequired
    @PostMapping("/skuInfoChangeInfoPush")
    @ApiOperation(value = "对接仓向Temu  商品信息修改", notes = "对接仓向Temu  商品信息修改")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = ProductQueryResponse.class))
    public SingleResult skuInfoChangeInfoPush(@RequestBody @Validated SkuInfoChangeReq req) {
        return service.skuInfoChangeInfoPush(req, 382L);
    }

    @PostMapping("/bg/certified/warehouse/inventory/batch/get")
    @ApiOperation(value = "Temu向对接仓 库存查询", notes = "Temu向对接仓  库存查询")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = InventoryQueryResponse.class))
    public InventoryQueryResponse getInventoryList(@RequestBody @Validated InventoryQueryReq req) {
        return service.getInventoryList(req);
    }


    @PostMapping("/bg/certified/warehouse/inventory/change/list/get")
    @ApiOperation(value = "Temu向对接仓 库存流水查询", notes = "Temu向对接仓  库存流水查询")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = InventoryChangeListResponse.class))
    public InventoryChangeListResponse inventoryChangeListGet(@RequestBody @Validated InventoryChangeListReq req) {
        return service.inventoryChangeListGet(req);
    }


    @PostMapping("/bg/certified/warehouse/order/create")
    @ApiOperation(value = "Temu向对接仓 合作仓履约订单下发", notes = "Temu向对接仓  合作仓履约订单下发")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = WarehouseOrderCreateResponse.class))
    public WarehouseOrderCreateResponse temuOrderCreate(@RequestBody @Validated WarehouseOrderCreateReq req) {
        return service.temuOrderCreate(req);
    }

    @PostMapping("/bg/certified/warehouse/order/info/get")
    @ApiOperation(value = "Temu向对接仓 订单信息查询接口", notes = "Temu向对接仓  订单信息查询接口")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = WarehouseOrderQueryResponse.class))
    public WarehouseOrderQueryResponse temuOrderQuery(@RequestBody @Validated WarehouseOrderQueryReq req) {
        return service.temuOrderQuery(req);
    }

    @PostMapping("/bg/certified/warehouse/outbound/order/fee/get")
    @ApiOperation(value = "Temu向对接仓 订单信息查询接口", notes = "Temu向对接仓  订单信息查询接口")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = WarehouseOrderFeeQueryResponse.class))
    public TemuBaseQueryRes<WarehouseOrderFeeQueryResponse> temuOrderFeeQuery(@RequestBody @Validated WarehouseOrderQueryReq req) {
        return service.temuOrderFeeQuery(req);
    }


    @PostMapping("/bg/certified/warehouse/order/createWithLabel")
    @ApiOperation(value = "Temu向对接仓 合作仓履约平台面单订单下发", notes = "Temu向对接仓  合作仓履约平台面单订单下发")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = WarehouseOrderCreateResponse.class))
    public WarehouseOrderCreateResponse temuOrderCreateWithLabel(@RequestBody @Validated OrderCreateWithLabelReq req) {
        return service.temuOrderCreateWithLabel(req);
    }


    @PostMapping("/bg/certified/warehouse/order/cancel")
    @ApiOperation(value = "Temu向对接仓 商家需要取消履约订单", notes = "Temu向对接仓  商家需要取消履约订单")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = TemuOrderCancelResponse.class))
    public TemuOrderCancelResponse temuOrderCancel(@RequestBody @Validated TemuOrderCancelReq req) {
        return service.temuOrderCancel(req);
    }

    @PostMapping("/bg/certified/warehouse/basic/get")
    @ApiOperation(value = "Temu向对接仓 获取仓库列表", notes = "Temu向对接仓  获取仓库列表")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = WarehouseInfoListResponse.class))
    public WarehouseInfoListResponse temuWarehouseInfoListGet(@RequestBody @Validated WarehouseInfoListReq req) {
        //对接仓接入后，初始化仓库列表信息bg.certified.warehouse.basic.get
        return service.temuWarehouseListGet(req);
    }

    @Deprecated
    @PostMapping("bg/certified/warehouse/order/tracking/get")
    @ApiOperation(value = "Temu向对接仓 订单发运后，查询轨迹信息（暂未实现）", notes = "Temu向对接仓  订单发运后，查询轨迹信息(暂未实现)")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = TrajectoryQueryResponse.class))
    public TrajectoryQueryResponse temuOrderListGet(@RequestBody @Validated TrajectoryQueryReq req) {
//        return service.trajectoryQuery(req);
        return TrajectoryQueryResponse.builder().errorMsg("暂未实现").errorCode(500).build();
    }


    @PostMapping("/bg/certified/warehouse/logistics/product/list/batch/get")
    @ApiOperation(value = "Temu向对接仓 temu 查询对接仓某个仓库支持物流产品列表", notes = "Temu向对接仓  temu 查询对接仓某个仓库支持物流产品列表")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = LogisticsProductListResponse.class))
    public LogisticsProductListResponse logisticsProductListBatchGet(@RequestBody @Validated LogisticsProductListGet req) {
        return service.logisticsProductListBatchGet(req);
    }


    @PostMapping("/bg/certified/warehouse/delivery/fee/calc")
    @ApiOperation(value = "Temu向对接仓 半托管合作对接仓预估派送费用接口", notes = "Temu向对接仓  半托管合作对接仓预估派送费用接口")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = DeliveryFeeCalcResponse.class))
    public DeliveryFeeCalcResponse deliveryFeeCalc(@RequestBody @Validated DeliveryFeeCalcReq req) {
        return service.deliveryFeeCalc(req);
    }

    @PostMapping("/bg/certified/warehouse/return/order/create")
    @ApiOperation(value = "Temu向对接仓 退货订单创建", notes = "Temu向对接仓 退货订单创建")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = TemuReturnOrderOperateResponse.class))
    public TemuReturnOrderOperateResponse temuReturnOrderCreate(@RequestBody @Validated TemuReturnOrderCreateReq req) {
        return service.temuReturnOrderCreate(req);
    }

    @PostMapping("/bg/certified/warehouse/return/order/update")
    @ApiOperation(value = "Temu向对接仓 退货订单修改", notes = "Temu向对接仓 退货订单修改")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = TemuReturnOrderOperateResponse.class))
    public TemuReturnOrderOperateResponse temuReturnOrderUpdate(@RequestBody @Validated TemuReturnOrderUpdateReq req) {
        return service.temuReturnOrderUpdate(req);
    }

    @PostMapping("/bg/certified/warehouse/return/order/cancel")
    @ApiOperation(value = "Temu向对接仓 退货单取消", notes = "Temu向对接仓 退货单取消")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = TemuReturnOrderOperateResponse.class))
    public TemuReturnOrderOperateResponse temuReturnOrderCancel(@RequestBody @Validated TemuReturnOrderCancelReq req) {
        return service.temuReturnOrderCancel(req);
    }
}

